<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/12/8
 * Time: 14:24
 */

require 'dbtool.php';

$username = $_POST['uesrname'];
$psd = $_POST['psd'];
$newUrl = '';
$msg = '';
session_start();

$conn = new mysqli();
$conn->connect('127.0.0.1','root','root','bank');
if(!empty($conn->connect_error)){
    echo 'MYSQL数据库连接错误: '.$conn->connect_error;
    die;
}
dbtool::setconn($conn);
$data = dbtool::selectconn('select * from bankcard');



for($i=0;$i<count($data);$i++){
    if ($username == $data[$i]['CardNo'] && $psd == $data[$i]['CardPwd']){
//  echo '登录成功';
//  header('location:userinfo.php');
    $keyValue = md5($username.$psd);
    setcookie('userkey',$keyValue,time()+24*3600,'/');
    $newUrl = 'userinfo.php';
    $msg = '登录成功';
    $_SESSION[$keyValue]=[
            'username'=>$username,
            'psd'=>$psd
    ];
    break;
    }else{
        //echo '用户名密码错误';
        //header('location:/login.php');
        $msg = '用户名或密码错误';
        $newUrl = '../login.php';
    }
}
?>


<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
</head>
<body>
    <input type="hidden" id="newUrl" value="<?php echo $newUrl;?>">
    <input type="hidden" id="msg" value="<?php echo $msg;?>">
</body>
<script>
    onload = function () {
        var newUrl = document.getElementById('newUrl').value;
        var msg = document.getElementById('msg').value;
        alert(msg);
        location.href = newUrl;
    }
</script>

</html>

